/*
 *   Copyright (C) 2011 David Swords
 *	
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package comm;
import java.util.Vector;
import java.io.*;

public class Parser {
	
	public Parser() {}

	public Vector< String > build(String input) {
		int l = 0, r = 0;
		Vector< String > data = new Vector< String >();
	
		for(int i = 0; i < input.length(); i++) {
			if(i == input.length() - 1 || input.charAt(i) == ' ') {
				r = i;
	
				if(l == 0) {
					data.add(input.substring(l, r));
				} else {
					if(r == input.length() - 1) {
						data.add(input.substring(l + 1, r + 1));
					} else {
						data.add(input.substring(l + 1, r));
					}
				}
	
				l = r;
			}
		}
	
		return data;
	}
	
	public static void main(String[] args) {
		Parser test = new Parser();
		Vector< String > data = test.build("5 R EE FFA2 000B FFA2 0000 0000 49C1");
		
		for(int i = 0; i < data.size(); i++) {
			System.out.println(data.get(i));
		}
	}
}
